package com.xiao.util;

import com.xiao.dao.PublishMessageMapper;
import com.xiao.dao.ResponseMessageMapper;
import com.xiao.pojo.Classrelation;
import com.xiao.pojo.Consultinfo;
import com.xiao.pojo.Examine;
import com.xiao.pojo.Message;

import java.util.List;
import java.util.stream.Collectors;


//发布消息的封装工具类
public class PublishUtil {
    //        根据随机数生成consultid
    private static Long a = (Long) System.currentTimeMillis();
    //        根据随机数生成messageid
    private static Long b = (Long) System.currentTimeMillis() + 1;

    public static void insertMesCon(Message message, List<Message> list1, List<Consultinfo> list2, Long[] classid, PublishMessageMapper publishMessageMapper) {
        for (long i : classid) {
            list1.add(new Message(b, message.getTitle(), message.getContent(), message.getAppendixsrc(), message.getEndtime(), message.getUid(), i, a, message.getSubjectid()));
            List<Classrelation> list = publishMessageMapper.finduidByclassid(i);
            list.forEach(e -> {
                list2.add(new Consultinfo(a, e.getUid(), b));
            });
        }

    }

    public static List<Message> filterMessage(String filter, long uid, ResponseMessageMapper responseMessageMapper) {
        List<Message> list = responseMessageMapper.queryAllMessage(uid);
        return list.stream().filter(a -> a.getMessagetype().getMessagetypename().equals(filter)).collect(Collectors.toList());

    }


}
